import {ref, computed} from 'vue'
import {defineStore} from "pinia";

export const useUserStore = defineStore('user', () => {
    const user = ref(null)
    const userInfo = computed(() => {
        return user.value
    })

    //更新token
    function updateUser(u) {
        user.value = u;
    }

    //重置token
    function $reset() {
        user.value = null;
    }

    return {user, userInfo, updateUser, $reset}
}, {
    persist: {
        key: "user",
        storage: sessionStorage,
        paths: ['user']
    }
})
